﻿#建议保存编码为：bom头 + utf8
param
(
	[parameter(Mandatory = $true)]
	[ValidateNotNullOrEmpty()]
	[Alias("cname")][String]$cluster名
)

& "${PSScriptRoot}/check_cds.ps1" $cluster名
if ($LASTEXITCODE -eq 0)
{
}
else
{
	& "${PSScriptRoot}/Write-Error2.ps1"  '错误：没有这个cluster,或cluster名字不合法。退出码1'
	exit 1
}

& "${PSScriptRoot}/_bak_rds.ps1"

Remove-Item -Force -Path "${PSScriptRoot}/prefix/*"
Remove-Item -Force -Path "${PSScriptRoot}/domains/*"

$private:rds = Get-Content -LiteralPath "${PSScriptRoot}/rds_1st.json" | ConvertFrom-Json -Depth 99
foreach ($temp001 in $private:rds.resources)
{
	$temp001.'virtual_hosts'.'routes'.'route'.'cluster' = $cluster名
}
$private:rds2 = $private:rds | ConvertTo-Json -Depth 99
Set-Content -LiteralPath "${PSScriptRoot}/rds.json" -Value $private:rds2 -Encoding utf8NoBOM

& "${PSScriptRoot}/_flashfile.ps1" "${PSScriptRoot}/rds.json"
& "${PSScriptRoot}/Write-Host2.ps1"  -ForegroundColor Green '信息：删除所有rds后，新建rds成功'
exit 0
